package com.core.website.scheduled;

import com.core.website.entity.Content;
import com.core.website.mapper.ContentMapper;
import com.core.website.service.ContentService;
import com.core.website.util.SpringUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;

/**
 * 点击数增加定时任务  每天的 10 点、15 点、20 点触发定时任务
 */
@Component
public class ClickNumScheduleTask {
    // api接口传递修改数量的值
    public Integer num;
    @Autowired
    private ContentMapper contentMapper;
    /**
     * num是接口传递过来改变值的内容
     * 默认会执行 加5个点击的操作
     */
    @Scheduled(cron = "0 0 10,15,20 * * ?")
    public void configureTasks() {
        if(null==contentMapper){
            System.out.println("contentMapper是空值 没有注入进来");
            contentMapper=SpringUtil.getBean(ContentMapper.class);
        }
        // 点击数增加10
        if(null != num){
            contentMapper.thumbsNum(num);
        }else{
            contentMapper.thumbsNum(1);
        }
        System.out.println("10 点、17 点、20 点触发一下清理任务。");
    }
}